home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d982.lha / HWGRCS / HWGdiffP1_2_6.lha / diffutils-2.6 / src / diff.info-3 (.txt) < prev    next >
GNU Info File  |  1993-12-16  |  47KB  |  918 lines

  1. This is Info file diff.info, produced by Makeinfo-1.55 from the input
  2. file ./diff.texi.
  3.    This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
  4. commands for showing the differences between text files and the `patch'
  5. command for using their output to update files.
  6.    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice are
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Foundation.
  18. File: diff.info,  Node: Making Patches,  Next: Invoking cmp,  Prev: Merging with patch,  Up: Top
  19. Tips for Making Patch Distributions
  20. ***********************************
  21.    Here are some things you should keep in mind if you are going to
  22. distribute patches for updating a software package.
  23.    Make sure you have specified the file names correctly, either in a
  24. context diff header or with an `Index:' line.  If you are patching
  25. files in a subdirectory, be sure to tell the patch user to specify a
  26. `-p' or `--strip' option as needed.  Take care to not send out reversed
  27. patches, since these make people wonder whether they have already
  28. applied the patch.
  29.    To save people from partially applying a patch before other patches
  30. that should have gone before it, you can make the first patch in the
  31. patch file update a file with a name like `patchlevel.h' or
  32. `version.c', which contains a patch level or version number.  If the
  33. input file contains the wrong version number, `patch' will complain
  34. immediately.
  35.    An even clearer way to prevent this problem is to put a `Prereq:'
  36. line before the patch.  If the leading text in the patch file contains a
  37. line that starts with `Prereq:', `patch' takes the next word from that
  38. line (normally a version number) and checks whether the next input file
  39. contains that word, preceded and followed by either white space or a
  40. newline.  If not, `patch' prompts you for confirmation before
  41. proceeding.  This makes it difficult to accidentally apply patches in
  42. the wrong order.
  43.    Since `patch' does not handle incomplete lines properly, make sure
  44. that all the source files in your program end with a newline whenever
  45. you release a version.
  46.    To create a patch that changes an older version of a package into a
  47. newer version, first make a copy of the older version in a scratch
  48. directory.  Typically you do that by unpacking a `tar' or `shar'
  49. archive of the older version.
  50.    You might be able to reduce the size of the patch by renaming or
  51. removing some files before making the patch.  If the older version of
  52. the package contains any files that the newer version does not, or if
  53. any files have been renamed between the two versions, make a list of
  54. `rm' and `mv' commands for the user to execute in the old version
  55. directory before applying the patch.  Then run those commands yourself
  56. in the scratch directory.
  57.    If there are any files that you don't need to include in the patch
  58. because they can easily be rebuilt from other files (for example,
  59. `TAGS' and output from `yacc' and `makeinfo'), replace the versions in
  60. the scratch directory with the newer versions, using `rm' and `ln' or
  61. `cp'.
  62.    Now you can create the patch.  The de-facto standard `diff' format
  63. for patch distributions is context format with two lines of context,
  64. produced by giving `diff' the `-C 2' option.  Do not use less than two
  65. lines of context, because `patch' typically needs at least two lines
  66. for proper operation.  Give `diff' the `-P' option in case the newer
  67. version of the package contains any files that the older one does not.
  68. Make sure to specify the scratch directory first and the newer
  69. directory second.
  70.    Add to the top of the patch a note telling the user any `rm' and
  71. `mv' commands to run before applying the patch.  Then you can remove
  72. the scratch directory.
  73. File: diff.info,  Node: Invoking cmp,  Next: Invoking diff,  Prev: Making Patches,  Up: Top
  74. Invoking `cmp'
  75. **************
  76.    The `cmp' command compares two files, and if they differ, tells the
  77. first byte and line number where they differ.  Its arguments are as
  78. follows:
  79.      cmp OPTIONS... FROM-FILE [TO-FILE]
  80.    The file name `-' is always the standard input.  `cmp' also uses the
  81. standard input if one file name is omitted.
  82.    An exit status of 0 means no differences were found, 1 means some
  83. differences were found, and 2 means trouble.
  84. * Menu:
  85. * cmp Options::        Summary of options to `cmp'.
  86. File: diff.info,  Node: cmp Options,  Up: Invoking cmp
  87. Options to `cmp'
  88. ================
  89.    Below is a summary of all of the options that GNU `cmp' accepts.
  90. Most options have two equivalent names, one of which is a single letter
  91. preceded by `-', and the other of which is a long name preceded by
  92. `--'.  Multiple single letter options (unless they take an argument)
  93. can be combined into a single command line word: `-cl' is equivalent to
  94. `-c -l'.
  95.      Print the differing characters.  Display control characters as a
  96.      `^' followed by a letter of the alphabet and precede characters
  97.      that have the high bit set with `M-' (which stands for "meta").
  98. `--ignore-initial=BYTES'
  99.      Ignore any differences in the the first BYTES bytes of the input
  100.      files.  Treat files with fewer than BYTES bytes as if they are
  101.      empty.
  102.      Print the (decimal) offsets and (octal) values of all differing
  103.      bytes.
  104. `--print-chars'
  105.      Print the differing characters.  Display control characters as a
  106.      `^' followed by a letter of the alphabet and precede characters
  107.      that have the high bit set with `M-' (which stands for "meta").
  108. `--quiet'
  109. `--silent'
  110.      Do not print anything; only return an exit status indicating
  111.      whether the files differ.
  112. `--verbose'
  113.      Print the (decimal) offsets and (octal) values of all differing
  114.      bytes.
  115. `--version'
  116.      Output the version number of `cmp'.
  117. File: diff.info,  Node: Invoking diff,  Next: Invoking diff3,  Prev: Invoking cmp,  Up: Top
  118. Invoking `diff'
  119. ***************
  120.    The format for running the `diff' command is:
  121.      diff OPTIONS... FROM-FILE TO-FILE
  122.    In the simplest case, `diff' compares the contents of the two files
  123. FROM-FILE and TO-FILE.  A file name of `-' stands for text read from
  124. the standard input.  As a special case, `diff - -' compares a copy of
  125. standard input to itself.
  126.    If FROM-FILE is a directory and TO-FILE is not, `diff' compares the
  127. file in FROM-FILE whose file name is that of TO-FILE, and vice versa.
  128. The non-directory file must not be `-'.
  129.    If both FROM-FILE and TO-FILE are directories, `diff' compares
  130. corresponding files in both directories, in alphabetical order; this
  131. comparison is not recursive unless the `-r' or `--recursive' option is
  132. given.  `diff' never compares the actual contents of a directory as if
  133. it were a file.  The file that is fully specified may not be standard
  134. input, because standard input is nameless and the notion of "file with
  135. the same name" does not apply.
  136.    `diff' options begin with `-', so normally FROM-FILE and TO-FILE may
  137. not begin with `-'.  However, `--' as an argument by itself treats the
  138. remaining arguments as file names even if they begin with `-'.
  139.    An exit status of 0 means no differences were found, 1 means some
  140. differences were found, and 2 means trouble.
  141. * Menu:
  142. * diff Options::    Summary of options to `diff'.
  143. File: diff.info,  Node: diff Options,  Up: Invoking diff
  144. Options to `diff'
  145. =================
  146.    Below is a summary of all of the options that GNU `diff' accepts.
  147. Most options have two equivalent names, one of which is a single letter
  148. preceded by `-', and the other of which is a long name preceded by
  149. `--'.  Multiple single letter options (unless they take an argument)
  150. can be combined into a single command line word: `-ac' is equivalent to
  151. `-a -c'.  Long named options can be abbreviated to any unique prefix of
  152. their name.  Brackets ([ and ]) indicate that an option takes an
  153. optional argument.
  154. `-LINES'
  155.      Show LINES (an integer) lines of context.  This option does not
  156.      specify an output format by itself; it has no effect unless it is
  157.      combined with `-c' (*note Context Format::.) or `-u' (*note
  158.      Unified Format::.).  This option is obsolete.  For proper
  159.      operation, `patch' typically needs at least two lines of context.
  160.      Treat all files as text and compare them line-by-line, even if they
  161.      do not seem to be text.  *Note Binary::.
  162.      Ignore changes in amount of white space.  *Note White Space::.
  163.      Ignore changes that just insert or delete blank lines.  *Note
  164.      Blank Lines::.
  165. `--brief'
  166.      Report only whether the files differ, not the details of the
  167.      differences.  *Note Brief::.
  168.      Use the context output format.  *Note Context Format::.
  169. `-C LINES'
  170. `--context[=LINES]'
  171.      Use the context output format, showing LINES (an integer) lines of
  172.      context, or three if LINES is not given.  *Note Context Format::.
  173.      For proper operation, `patch' typically needs at least two lines of
  174.      context.
  175. `--changed-group-format=FORMAT'
  176.      Use FORMAT to output a line group containing differing lines from
  177.      both files in if-then-else format.  *Note Line Group Formats::.
  178.      Change the algorithm perhaps find a smaller set of changes.  This
  179.      makes `diff' slower (sometimes much slower).  *Note diff
  180.      Performance::.
  181. `-D NAME'
  182.      Make merged `#ifdef' format output, conditional on the preprocessor
  183.      macro NAME.  *Note If-then-else::.
  184. `--ed'
  185.      Make output that is a valid `ed' script.  *Note ed Scripts::.
  186. `--exclude=PATTERN'
  187.      When comparing directories, ignore files and subdirectories whose
  188.      basenames match PATTERN.  *Note Comparing Directories::.
  189. `--exclude-from=FILE'
  190.      When comparing directories, ignore files and subdirectories whose
  191.      basenames match any pattern contained in FILE.  *Note Comparing
  192.      Directories::.
  193. `--expand-tabs'
  194.      Expand tabs to spaces in the output, to preserve the alignment of
  195.      tabs in the input files.  *Note Tabs::.
  196.      Make output that looks vaguely like an `ed' script but has changes
  197.      in the order they appear in the file.  *Note Forward ed::.
  198. `-F REGEXP'
  199.      In context and unified format, for each hunk of differences, show
  200.      some of the last preceding line that matches REGEXP.  *Note
  201.      Specified Headings::.
  202. `--forward-ed'
  203.      Make output that looks vaguely like an `ed' script but has changes
  204.      in the order they appear in the file.  *Note Forward ed::.
  205.      This option currently has no effect; it is present for Unix
  206.      compatibility.
  207.      Use heuristics to speed handling of large files that have numerous
  208.      scattered small changes.  *Note diff Performance::.
  209. `--horizon-lines=LINES'
  210.      Do not discard the last LINES lines of the common prefix and the
  211.      first LINES lines of the common suffix.  *Note diff Performance::.
  212.      Ignore changes in case; consider upper- and lower-case letters
  213.      equivalent.  *Note Case Folding::.
  214. `-I REGEXP'
  215.      Ignore changes that just insert or delete lines that match REGEXP.
  216.      *Note Specified Folding::.
  217. `--ifdef=NAME'
  218.      Make merged if-then-else output using FORMAT.  *Note
  219.      If-then-else::.
  220. `--ignore-all-space'
  221.      Ignore white space when comparing lines.  *Note White Space::.
  222. `--ignore-blank-lines'
  223.      Ignore changes that just insert or delete blank lines.  *Note
  224.      Blank Lines::.
  225. `--ignore-case'
  226.      Ignore changes in case; consider upper- and lower-case to be the
  227.      same.  *Note Case Folding::.
  228. `--ignore-matching-lines=REGEXP'
  229.      Ignore changes that just insert or delete lines that match REGEXP.
  230.      *Note Specified Folding::.
  231. `--ignore-space-change'
  232.      Ignore changes in amount of white space.  *Note White Space::.
  233. `--initial-tab'
  234.      Output a tab rather than a space before the text of a line in
  235.      normal or context format.  This causes the alignment of tabs in
  236.      the line to look normal.  *Note Tabs::.
  237.      Pass the output through `pr' to paginate it.  *Note Pagination::.
  238. `-L LABEL'
  239.      Use LABEL instead of the file name in the context format (*note
  240.      Context Format::.) and unified format (*note Unified Format::.)
  241.      headers.  *Note RCS::.
  242. `--label=LABEL'
  243.      Use LABEL instead of the file name in the context format (*note
  244.      Context Format::.) and unified format (*note Unified Format::.)
  245.      headers.
  246. `--left-column'
  247.      Print only the left column of two common lines in side by side
  248.      format.  *Note Side by Side Format::.
  249. `--line-format=FORMAT'
  250.      Use FORMAT to output all input lines in if-then-else format.
  251.      *Note Line Formats::.
  252. `--minimal'
  253.      Change the algorithm to perhaps find a smaller set of changes.
  254.      This makes `diff' slower (sometimes much slower).  *Note diff
  255.      Performance::.
  256.      Output RCS-format diffs; like `-f' except that each command
  257.      specifies the number of lines affected.  *Note RCS::.
  258. `--new-file'
  259.      In directory comparison, if a file is found in only one directory,
  260.      treat it as present but empty in the other directory.  *Note
  261.      Comparing Directories::.
  262. `--new-group-format=FORMAT'
  263.      Use FORMAT to output a group of lines taken from just the second
  264.      file in if-then-else format.  *Note Line Group Formats::.
  265. `--new-line-format=FORMAT'
  266.      Use FORMAT to output a line taken from just the second file in
  267.      if-then-else format.  *Note Line Formats::.
  268. `--old-group-format=FORMAT'
  269.      Use FORMAT to output a group of lines taken from just the first
  270.      file in if-then-else format.  *Note Line Group Formats::.
  271. `--old-line-format=FORMAT'
  272.      Use FORMAT to output a line taken from just the first file in
  273.      if-then-else format.  *Note Line Formats::.
  274.      Show which C function each change is in.  *Note C Function
  275.      Headings::.
  276.      When comparing directories, if a file appears only in the second
  277.      directory of the two, treat it as present but empty in the other.
  278.      *Note Comparing Directories::.
  279. `--paginate'
  280.      Pass the output through `pr' to paginate it.  *Note Pagination::.
  281.      Report only whether the files differ, not the details of the
  282.      differences.  *Note Brief::.
  283.      When comparing directories, recursively compare any subdirectories
  284.      found.  *Note Comparing Directories::.
  285. `--rcs'
  286.      Output RCS-format diffs; like `-f' except that each command
  287.      specifies the number of lines affected.  *Note RCS::.
  288. `--recursive'
  289.      When comparing directories, recursively compare any subdirectories
  290.      found.  *Note Comparing Directories::.
  291. `--report-identical-files'
  292.      Report when two files are the same.  *Note Comparing Directories::.
  293.      Report when two files are the same.  *Note Comparing Directories::.
  294. `-S FILE'
  295.      When comparing directories, start with the file FILE.  This is
  296.      used for resuming an aborted comparison.  *Note Comparing
  297.      Directories::.
  298. `--sdiff-merge-assist'
  299.      Print extra information to help `sdiff'.  `sdiff' uses this option
  300.      when it runs `diff'.  This option is not intended for users to use
  301.      directly.
  302. `--show-c-function'
  303.      Show which C function each change is in.  *Note C Function
  304.      Headings::.
  305. `--show-function-line=REGEXP'
  306.      In context and unified format, for each hunk of differences, show
  307.      some of the last preceding line that matches REGEXP.  *Note
  308.      Specified Headings::.
  309. `--side-by-side'
  310.      Use the side by side output format.  *Note Side by Side Format::.
  311. `--speed-large-files'
  312.      Use heuristics to speed handling of large files that have numerous
  313.      scattered small changes.  *Note diff Performance::.
  314. `--starting-file=FILE'
  315.      When comparing directories, start with the file FILE.  This is
  316.      used for resuming an aborted comparison.  *Note Comparing
  317.      Directories::.
  318. `--suppress-common-lines'
  319.      Do not print common lines in side by side format.  *Note Side by
  320.      Side Format::.
  321.      Expand tabs to spaces in the output, to preserve the alignment of
  322.      tabs in the input files.  *Note Tabs::.
  323.      Output a tab rather than a space before the text of a line in
  324.      normal or context format.  This causes the alignment of tabs in
  325.      the line to look normal.  *Note Tabs::.
  326. `--text'
  327.      Treat all files as text and compare them line-by-line, even if they
  328.      do not appear to be text.  *Note Binary::.
  329.      Use the unified output format.  *Note Unified Format::.
  330. `--unchanged-group-format=FORMAT'
  331.      Use FORMAT to output a group of common lines taken from both files
  332.      in if-then-else format.  *Note Line Group Formats::.
  333. `--unchanged-line-format=FORMAT'
  334.      Use FORMAT to output a line common to both files in if-then-else
  335.      format.  *Note Line Formats::.
  336. `--unidirectional-new-file'
  337.      When comparing directories, if a file appears only in the second
  338.      directory of the two, treat it as present but empty in the other.
  339.      *Note Comparing Directories::.
  340. `-U LINES'
  341. `--unified[=LINES]'
  342.      Use the unified output format, showing LINES (an integer) lines of
  343.      context, or three if LINES is not given.  *Note Unified Format::.
  344.      For proper operation, `patch' typically needs at least two lines of
  345.      context.
  346. `--version'
  347.      Output the version number of `diff'.
  348.      Ignore white space when comparing lines.  *Note White Space::.
  349. `-W COLUMNS'
  350. `--width=COLUMNS'
  351.      Use an output width of COLUMNS in side by side format.  *Note Side
  352.      by Side Format::.
  353. `-x PATTERN'
  354.      When comparing directories, ignore files and subdirectories whose
  355.      basenames match PATTERN.  *Note Comparing Directories::.
  356. `-X FILE'
  357.      When comparing directories, ignore files and subdirectories whose
  358.      basenames match any pattern contained in FILE.  *Note Comparing
  359.      Directories::.
  360.      Use the side by side output format.  *Note Side by Side Format::.
  361. File: diff.info,  Node: Invoking diff3,  Next: Invoking patch,  Prev: Invoking diff,  Up: Top
  362. Invoking `diff3'
  363. ****************
  364.    The `diff3' command compares three files and outputs descriptions of
  365. their differences.  Its arguments are as follows:
  366.      diff3 OPTIONS... MINE OLDER YOURS
  367.    The files to compare are MINE, OLDER, and YOURS.  At most one of
  368. these three file names may be `-', which tells `diff3' to read the
  369. standard input for that file.
  370.    An exit status of 0 means `diff3' was successful, 1 means some
  371. conflicts were found, and 2 means trouble.
  372. * Menu:
  373. * diff3 Options::        Summary of options to `diff3'.
  374. File: diff.info,  Node: diff3 Options,  Up: Invoking diff3
  375. Options to `diff3'
  376. ==================
  377.    Below is a summary of all of the options that GNU `diff3' accepts.
  378. Multiple single letter options (unless they take an argument) can be
  379. combined into a single command line argument.
  380.      Treat all files as text and compare them line-by-line, even if they
  381.      do not appear to be text.  *Note Binary::.
  382.      Incorporate all changes from OLDER to YOURS into MINE, surrounding
  383.      all conflicts with bracket lines.  *Note Marking Conflicts::.
  384.      Generate an `ed' script that incorporates all the changes from
  385.      OLDER to YOURS into MINE.  *Note Which Changes::.
  386.      Like `-e', except bracket lines from overlapping changes' first
  387.      and third files.  *Note Marking Conflicts::.  With `-e', an
  388.      overlapping change looks like this:
  389.           <<<<<<< MINE
  390.           lines from MINE
  391.           =======
  392.           lines from YOURS
  393.           >>>>>>> YOURS
  394. `--ed'
  395.      Generate an `ed' script that incorporates all the changes from
  396.      OLDER to YOURS into MINE.  *Note Which Changes::.
  397. `--easy-only'
  398.      Like `-e', except output only the nonoverlapping changes.  *Note
  399.      Which Changes::.
  400.      Generate `w' and `q' commands at the end of the `ed' script for
  401.      System V compatibility.  This option must be combined with one of
  402.      the `-AeExX3' options, and may not be combined with `-m'.  *Note
  403.      Saving the Changed File::.
  404. `--initial-tab'
  405.      Output a tab rather than two spaces before the text of a line in
  406.      normal format.  This causes the alignment of tabs in the line to
  407.      look normal.  *Note Tabs::.
  408. `-L LABEL'
  409. `--label=LABEL'
  410.      Use the label LABEL for the brackets output by the `-A', `-E' and
  411.      `-X' options.  This option may be given up to three times, one for
  412.      each input file.  The default labels are the names of the input
  413.      files.  Thus `diff3 -L X -L Y -L Z -m A B C' acts like `diff3 -m A
  414.      B C', except that the output looks like it came from files named
  415.      `X', `Y' and `Z' rather than from files named `A', `B' and `C'.
  416.      *Note Marking Conflicts::.
  417. `--merge'
  418.      Apply the edit script to the first file and send the result to
  419.      standard output.  Unlike piping the output from `diff3' to `ed',
  420.      this works even for binary files and incomplete lines.  `-A' is
  421.      assumed if no edit script option is specified.  *Note Bypassing
  422.      ed::.
  423. `--overlap-only'
  424.      Like `-e', except output only the overlapping changes.  *Note
  425.      Which Changes::.
  426. `--show-all'
  427.      Incorporate all unmerged changes from OLDER to YOURS into MINE,
  428.      surrounding all overlapping changes with bracket lines.  *Note
  429.      Marking Conflicts::.
  430. `--show-overlap'
  431.      Like `-e', except bracket lines from overlapping changes' first
  432.      and third files.  *Note Marking Conflicts::.
  433.      Output a tab rather than two spaces before the text of a line in
  434.      normal format.  This causes the alignment of tabs in the line to
  435.      look normal.  *Note Tabs::.
  436. `--text'
  437.      Treat all files as text and compare them line-by-line, even if they
  438.      do not appear to be text.  *Note Binary::.
  439. `--version'
  440.      Output the version number of `diff3'.
  441.      Like `-e', except output only the overlapping changes.  *Note
  442.      Which Changes::.
  443.      Like `-E', except output only the overlapping changes.  In other
  444.      words, like `-x', except bracket changes as in `-E'.  *Note
  445.      Marking Conflicts::.
  446.      Like `-e', except output only the nonoverlapping changes.  *Note
  447.      Which Changes::.
  448. File: diff.info,  Node: Invoking patch,  Next: Invoking sdiff,  Prev: Invoking diff3,  Up: Top
  449. Invoking `patch'
  450. ****************
  451.    Normally `patch' is invoked like this:
  452.      patch <PATCHFILE
  453.    The full format for invoking `patch' is:
  454.      patch OPTIONS... [ORIGFILE [PATCHFILE]] [+ OPTIONS... [ORIGFILE]]...
  455.    If you do not specify PATCHFILE, or if PATCHFILE is `-', `patch'
  456. reads the patch (that is, the `diff' output) from the standard input.
  457.    You can specify one or more of the original files as ORIG arguments;
  458. each one and options for interpreting it is separated from the others
  459. with a `+'.  *Note Multiple Patches::, for more information.
  460.    If you do not specify an input file on the command line, `patch'
  461. tries to figure out from the "leading text" (any text in the patch that
  462. comes before the `diff' output) which file to edit.  In the header of a
  463. context or unified diff, `patch' looks in lines beginning with `***',
  464. `---', or `+++'; among those, it chooses the shortest name of an
  465. existing file.  Otherwise, if there is an `Index:' line in the leading
  466. text, `patch' tries to use the file name from that line.  If `patch'
  467. cannot figure out the name of an existing file from the leading text,
  468. it prompts you for the name of the file to patch.
  469.    If the input file does not exist or is read-only, and a suitable RCS
  470. or SCCS file exists, `patch' attempts to check out or get the file
  471. before proceeding.
  472.    By default, `patch' replaces the original input file with the
  473. patched version, after renaming the original file into a backup file
  474. (*note Backups::., for a description of how `patch' names backup
  475. files).  You can also specify where to put the output with the `-o
  476. OUTPUT-FILE' or `--output=OUTPUT-FILE' option.
  477. * Menu:
  478. * patch Directories::    Changing directory and stripping paths.
  479. * Backups::        Backup file names.
  480. * Rejects::        Reject file names.
  481. * patch Options::    Summary table of options to `patch'.
  482. File: diff.info,  Node: patch Directories,  Next: Backups,  Up: Invoking patch
  483. Applying Patches in Other Directories
  484. =====================================
  485.    The `-d DIRECTORY' or `--directory=DIRECTORY' option to `patch'
  486. makes directory DIRECTORY the current directory for interpreting both
  487. file names in the patch file, and file names given as arguments to
  488. other options (such as `-B' and `-o').  For example, while in a news
  489. reading program, you can patch a file in the `/usr/src/emacs' directory
  490. directly from the article containing the patch like this:
  491.      | patch -d /usr/src/emacs
  492.    Sometimes the file names given in a patch contain leading
  493. directories, but you keep your files in a directory different from the
  494. one given in the patch.  In those cases, you can use the `-p[NUMBER]'
  495. or `--strip[=NUMBER]' option to set the file name strip count to
  496. NUMBER.  The strip count tells `patch' how many slashes, along with the
  497. directory names between them, to strip from the front of file names.
  498. `-p' with no NUMBER given is equivalent to `-p0'.  By default, `patch'
  499. strips off all leading paths, leaving just the base file names, except
  500. that when a file name given in the patch is a relative path and all of
  501. its leading directories already exist, `patch' does not strip off the
  502. leading path.  (A "relative" path is one that does not start with a
  503. slash.)
  504.    `patch' looks for each file (after any slashes have been stripped)
  505. in the current directory, or if you used the `-d DIRECTORY' option, in
  506. that directory.
  507.    For example, suppose the file name in the patch file is
  508. `/gnu/src/emacs/etc/NEWS'.  Using `-p' or `-p0' gives the entire file
  509. name unmodified, `-p1' gives `gnu/src/emacs/etc/NEWS' (no leading
  510. slash), `-p4' gives `etc/NEWS', and not specifying `-p' at all gives
  511. `NEWS'.
  512. File: diff.info,  Node: Backups,  Next: Rejects,  Prev: patch Directories,  Up: Invoking patch
  513. Backup File Names
  514. =================
  515.    Normally, `patch' renames an original input file into a backup file
  516. by appending to its name the extension `.orig', or `~' on systems that
  517. do not support long file names.  The `-b BACKUP-SUFFIX' or
  518. `--suffix=BACKUP-SUFFIX' option uses BACKUP-SUFFIX as the backup
  519. extension instead.
  520.    Alternately, you can specify the extension for backup files with the
  521. `SIMPLE_BACKUP_SUFFIX' environment variable, which the options override.
  522.    `patch' can also create numbered backup files the way GNU Emacs
  523. does.  With this method, instead of having a single backup of each file,
  524. `patch' makes a new backup file name each time it patches a file.  For
  525. example, the backups of a file named `sink' would be called,
  526. successively, `sink.~1~', `sink.~2~', `sink.~3~', etc.
  527.    The `-V BACKUP-STYLE' or `--version-control=BACKUP-STYLE' option
  528. takes as an argument a method for creating backup file names.  You can
  529. alternately control the type of backups that `patch' makes with the
  530. `VERSION_CONTROL' environment variable, which the `-V' option
  531. overrides.  The value of the `VERSION_CONTROL' environment variable and
  532. the argument to the `-V' option are like the GNU Emacs
  533. `version-control' variable (*note emacs: Backups., for more information
  534. on backup versions in Emacs).  They also recognize synonyms that are
  535. more descriptive.  The valid values are listed below; unique
  536. abbreviations are acceptable.
  537. `numbered'
  538.      Always make numbered backups.
  539. `nil'
  540. `existing'
  541.      Make numbered backups of files that already have them, simple
  542.      backups of the others.  This is the default.
  543. `never'
  544. `simple'
  545.      Always make simple backups.
  546.    Alternately, you can tell `patch' to prepend a prefix, such as a
  547. directory name, to produce backup file names.  The `-B BACKUP-PREFIX'
  548. or `--prefix=BACKUP-PREFIX' option makes backup files by prepending
  549. BACKUP-PREFIX to them.  If you use this option, `patch' ignores any
  550. `-b' option that you give.
  551.    If the backup file already exists, `patch' creates a new backup file
  552. name by changing the first lowercase letter in the last component of
  553. the file name into uppercase.  If there are no more lowercase letters
  554. in the name, it removes the first character from the name.  It repeats
  555. this process until it comes up with a backup file name that does not
  556. already exist.
  557.    If you specify the output file with the `-o' option, that file is
  558. the one that is backed up, not the input file.
  559. File: diff.info,  Node: Rejects,  Next: patch Options,  Prev: Backups,  Up: Invoking patch
  560. Reject File Names
  561. =================
  562.    The names for reject files (files containing patches that `patch'
  563. could not find a place to apply) are normally the name of the output
  564. file with `.rej' appended (or `#' on systems that do not support long
  565. file names).
  566.    Alternatively, you can tell `patch' to place all of the rejected
  567. patches in a single file.  The `-r REJECT-FILE' or
  568. `--reject-file=REJECT-FILE' option uses REJECT-FILE as the reject file
  569. name.
  570. File: diff.info,  Node: patch Options,  Prev: Rejects,  Up: Invoking patch
  571. Options to `patch'
  572. ==================
  573.    Here is a summary of all of the options that `patch' accepts.  Older
  574. versions of `patch' do not accept long-named options or the `-t', `-E',
  575. or `-V' options.
  576.    Multiple single-letter options that do not take an argument can be
  577. combined into a single command line argument (with only one dash).
  578. Brackets ([ and ]) indicate that an option takes an optional argument.
  579. `-b BACKUP-SUFFIX'
  580.      Use BACKUP-SUFFIX as the backup extension instead of `.orig' or
  581.      `~'.  *Note Backups::.
  582. `-B BACKUP-PREFIX'
  583.      Use BACKUP-PREFIX as a prefix to the backup file name.  If this
  584.      option is specified, any `-b' option is ignored.  *Note Backups::.
  585. `--batch'
  586.      Do not ask any questions.  *Note patch Messages::.
  587. `--context'
  588.      Interpret the patch file as a context diff.  *Note patch Input::.
  589. `-d DIRECTORY'
  590. `--directory=DIRECTORY'
  591.      Makes directory DIRECTORY the current directory for interpreting
  592.      both file names in the patch file, and file names given as
  593.      arguments to other options.  *Note patch Directories::.
  594. `-D NAME'
  595.      Make merged if-then-else output using FORMAT.  *Note
  596.      If-then-else::.
  597. `--debug=NUMBER'
  598.      Set internal debugging flags.  Of interest only to `patch'
  599.      patchers.
  600. `--ed'
  601.      Interpret the patch file as an `ed' script.  *Note patch Input::.
  602.      Remove output files that are empty after the patches have been
  603.      applied.  *Note Empty Files::.
  604.      Assume that the user knows exactly what he or she is doing, and do
  605.      not ask any questions.  *Note patch Messages::.
  606. `-F LINES'
  607.      Set the maximum fuzz factor to LINES.  *Note Inexact::.
  608. `--force'
  609.      Assume that the user knows exactly what he or she is doing, and do
  610.      not ask any questions.  *Note patch Messages::.
  611. `--forward'
  612.      Ignore patches that `patch' thinks are reversed or already applied.
  613.      See also `-R'.  *Note Reversed Patches::.
  614. `--fuzz=LINES'
  615.      Set the maximum fuzz factor to LINES.  *Note Inexact::.
  616. `--help'
  617.      Print a summary of the options that `patch' recognizes, then exit.
  618. `--ifdef=NAME'
  619.      Make merged if-then-else output using FORMAT.  *Note
  620.      If-then-else::.
  621. `--ignore-white-space'
  622.      Let any sequence of white space in the patch file match any
  623.      sequence of white space in the input file.  *Note Changed White
  624.      Space::.
  625. `--normal'
  626.      Interpret the patch file as a normal diff.  *Note patch Input::.
  627.      Ignore patches that `patch' thinks are reversed or already applied.
  628.      See also `-R'.  *Note Reversed Patches::.
  629. `-o OUTPUT-FILE'
  630. `--output=OUTPUT-FILE'
  631.      Use OUTPUT-FILE as the output file name.  *Note patch Options::.
  632. `-p[NUMBER]'
  633.      Set the file name strip count to NUMBER.  *Note patch
  634.      Directories::.
  635. `--prefix=BACKUP-PREFIX'
  636.      Use BACKUP-PREFIX as a prefix to the backup file name.  If this
  637.      option is specified, any `-b' option is ignored.  *Note Backups::.
  638. `--quiet'
  639.      Work silently unless an error occurs.  *Note patch Messages::.
  640. `-r REJECT-FILE'
  641.      Use REJECT-FILE as the reject file name.  *Note Rejects::.
  642.      Assume that this patch was created with the old and new files
  643.      swapped.  *Note Reversed Patches::.
  644. `--reject-file=REJECT-FILE'
  645.      Use REJECT-FILE as the reject file name.  *Note Rejects::.
  646. `--remove-empty-files'
  647.      Remove output files that are empty after the patches have been
  648.      applied.  *Note Empty Files::.
  649. `--reverse'
  650.      Assume that this patch was created with the old and new files
  651.      swapped.  *Note Reversed Patches::.
  652.      Work silently unless an error occurs.  *Note patch Messages::.
  653.      Ignore this patch from the patch file, but continue looking for
  654.      the next patch in the file.  *Note Multiple Patches::.
  655. `--silent'
  656.      Work silently unless an error occurs.  *Note patch Messages::.
  657. `--skip'
  658.      Ignore this patch from the patch file, but continue looking for
  659.      the next patch in the file.  *Note Multiple Patches::.
  660. `--strip[=NUMBER]'
  661.      Set the file name strip count to NUMBER.  *Note patch
  662.      Directories::.
  663. `--suffix=BACKUP-SUFFIX'
  664.      Use BACKUP-SUFFIX as the backup extension instead of `.orig' or
  665.      `~'.  *Note Backups::.
  666.      Do not ask any questions.  *Note patch Messages::.
  667. `--unified'
  668.      Interpret the patch file as a unified diff.  *Note patch Input::.
  669.      Output the revision header and patch level of `patch'.
  670. `-V BACKUP-STYLE'
  671.      Select the kind of backups to make.  *Note Backups::.
  672. `--version'
  673.      Output the revision header and patch level of `patch', then exit.
  674. `--version=control=BACKUP-STYLE'
  675.      Select the kind of backups to make.  *Note Backups::.
  676. `-x NUMBER'
  677.      Set internal debugging flags.  Of interest only to `patch'
  678.      patchers.
  679. File: diff.info,  Node: Invoking sdiff,  Next: Incomplete Lines,  Prev: Invoking patch,  Up: Top
  680. Invoking `sdiff'
  681. ****************
  682.    The `sdiff' command merges two files and interactively outputs the
  683. results.  Its arguments are as follows:
  684.      sdiff -o OUTFILE OPTIONS... FROM-FILE TO-FILE
  685.    This merges FROM-FILE with TO-FILE, with output to OUTFILE.  If
  686. FROM-FILE is a directory and TO-FILE is not, `sdiff' compares the file
  687. in FROM-FILE whose file name is that of TO-FILE, and vice versa.
  688. fROM-FILE and TO-FILE may not both be directories.
  689.    `sdiff' options begin with `-', so normally FROM-FILE and TO-FILE
  690. may not begin with `-'.  However, `--' as an argument by itself treats
  691. the remaining arguments as file names even if they begin with `-'.  You
  692. may not use `-' as an input file.
  693.    An exit status of 0 means no differences were found, 1 means some
  694. differences were found, and 2 means trouble.
  695.    `sdiff' without `-o' (or `--output') produces a side-by-side
  696. difference.  This usage is obsolete; use `diff --side-by-side' instead.
  697. * Menu:
  698. * sdiff Options::    Summary of options to `diff'.
  699. File: diff.info,  Node: sdiff Options,  Up: Invoking sdiff
  700. Options to `sdiff'
  701. ==================
  702.    Below is a summary of all of the options that GNU `sdiff' accepts.
  703. Each option has two equivalent names, one of which is a single letter
  704. preceded by `-', and the other of which is a long name preceded by
  705. `--'.  Multiple single letter options (unless they take an argument)
  706. can be combined into a single command line argument.  Long named
  707. options can be abbreviated to any unique prefix of their name.
  708.      Treat all files as text and compare them line-by-line, even if they
  709.      do not appear to be text.  *Note Binary::.
  710.      Ignore changes in amount of white space.  *Note White Space::.
  711.      Ignore changes that just insert or delete blank lines.  *Note
  712.      Blank Lines::.
  713.      Change the algorithm to perhaps find a smaller set of changes.
  714.      This makes `sdiff' slower (sometimes much slower).  *Note diff
  715.      Performance::.
  716.      Use heuristics to speed handling of large files that have numerous
  717.      scattered small changes.  *Note diff Performance::.
  718. `--expand-tabs'
  719.      Expand tabs to spaces in the output, to preserve the alignment of
  720.      tabs in the input files.  *Note Tabs::.
  721.      Ignore changes in case; consider upper- and lower-case to be the
  722.      same.  *Note Case Folding::.
  723. `-I REGEXP'
  724.      Ignore changes that just insert or delete lines that match REGEXP.
  725.      *Note Specified Folding::.
  726. `--ignore-all-space'
  727.      Ignore white space when comparing lines.  *Note White Space::.
  728. `--ignore-blank-lines'
  729.      Ignore changes that just insert or delete blank lines.  *Note
  730.      Blank Lines::.
  731. `--ignore-case'
  732.      Ignore changes in case; consider upper- and lower-case to be the
  733.      same.  *Note Case Folding::.
  734. `--ignore-matching-lines=REGEXP'
  735.      Ignore changes that just insert or delete lines that match REGEXP.
  736.      *Note Specified Folding::.
  737. `--ignore-space-change'
  738.      Ignore changes in amount of white space.  *Note White Space::.
  739. `--left-column'
  740.      Print only the left column of two common lines.  *Note Side by
  741.      Side Format::.
  742. `--minimal'
  743.      Change the algorithm to perhaps find a smaller set of changes.
  744.      This makes `sdiff' slower (sometimes much slower).  *Note diff
  745.      Performance::.
  746. `-o FILE'
  747. `--output=FILE'
  748.      Put merged output into FILE.  This option is required for merging.
  749. `--suppress-common-lines'
  750.      Do not print common lines.  *Note Side by Side Format::.
  751. `--speed-large-files'
  752.      Use heuristics to speed handling of large files that have numerous
  753.      scattered small changes.  *Note diff Performance::.
  754.      Expand tabs to spaces in the output, to preserve the alignment of
  755.      tabs in the input files.  *Note Tabs::.
  756. `--text'
  757.      Treat all files as text and compare them line-by-line, even if they
  758.      do not appear to be text.  *Note Binary::.
  759. `--version'
  760.      Output the version number of `sdiff'.
  761. `-w COLUMNS'
  762. `--width=COLUMNS'
  763.      Use an output width of COLUMNS.  *Note Side by Side Format::.
  764.      Note that for historical reasons, this option is `-W' in `diff',
  765.      `-w' in `sdiff'.
  766.      Ignore horizontal white space when comparing lines.  *Note White
  767.      Space::.  Note that for historical reasons, this option is `-w' in
  768.      `diff', `-W' in `sdiff'.
  769. File: diff.info,  Node: Incomplete Lines,  Next: Projects,  Prev: Invoking sdiff,  Up: Top
  770. Incomplete Lines
  771. ****************
  772.    When an input file ends in a non-newline character, its last line is
  773. called an "incomplete line" because its last character is not a
  774. newline.  All other lines are called "full lines" and end in a newline
  775. character.  Incomplete lines do not match full lines unless differences
  776. in blank lines are ignored (*note Blank Lines::.).
  777.    An incomplete line is normally distinguished on output from a full
  778. line by a following line that starts with `\'.  However, the RCS format
  779. (*note RCS::.) outputs the incomplete line as-is, without any trailing
  780. newline or following line.  The side by side format normally represents
  781. incomplete lines as-is, but in some cases uses a `\' or `/' gutter
  782. marker; *Note Side by Side::.  The if-then-else line format preserves a
  783. line's incompleteness with `%L', and discards the newline with `%l';
  784. *Note Line Formats::.  Finally, with the `ed' and forward `ed' output
  785. formats (*note Output Formats::.) `diff' cannot represent an incomplete
  786. line, so it pretends there was a newline and reports an error.
  787.    For example, suppose `F' and `G' are one-byte files that contain
  788. just `f' and `g', respectively.  Then `diff F G' outputs
  789.      1c1
  790.      < f
  791.      \ No newline at end of file
  792.      ---
  793.      > g
  794.      \ No newline at end of file
  795. (The exact message may differ in non-English locales.) `diff -n F G'
  796. outputs the following without a trailing newline:
  797.      d1 1
  798.      a1 1
  799.      g
  800.    `diff -e F G' reports two errors and outputs the following:
  801.      1c
  802.      g
  803.      .
  804. File: diff.info,  Node: Projects,  Next: Concept Index,  Prev: Incomplete Lines,  Up: Top
  805. Future Projects
  806. ***************
  807.    Here are some ideas for improving GNU `diff' and `patch'.  The GNU
  808. project has identified some improvements as potential programming
  809. projects for volunteers.  You can also help by reporting any bugs that
  810. you find.
  811.    If you are a programmer and would like to contribute something to the
  812. GNU project, please consider volunteering for one of these projects.  If
  813. you are seriously contemplating work, please write to
  814. `gnu@prep.ai.mit.edu' to coordinate with other volunteers.
  815. * Menu:
  816. * Shortcomings::    Suggested projects for improvements.
  817. * Bugs::        Reporting bugs.
  818. File: diff.info,  Node: Shortcomings,  Next: Bugs,  Up: Projects
  819. Suggested Projects for Improving GNU `diff' and `patch'
  820. =======================================================
  821.    One should be able to use GNU `diff' to generate a patch from any
  822. pair of directory trees, and given the patch and a copy of one such
  823. tree, use `patch' to generate a faithful copy of the other.
  824. Unfortunately, some changes to directory trees cannot be expressed using
  825. current patch formats; also, `patch' does not handle some of the
  826. existing formats.  These shortcomings motivate the following suggested
  827. projects.
  828. * Menu:
  829. * Changing Structure::    Handling changes to the directory structure.
  830. * Special Files::    Handling symbolic links, device special files, etc.
  831. * Unusual File Names::    Handling file names that contain unusual characters.
  832. * Arbitrary Limits::    Patching non-text files.
  833. * Large Files::        Handling files that do not fit in memory.
  834. * Ignoring Changes::    Ignoring certain changes while showing others.
  835. File: diff.info,  Node: Changing Structure,  Next: Special Files,  Up: Shortcomings
  836. Handling Changes to the Directory Structure
  837. -------------------------------------------
  838.    `diff' and `patch' do not handle some changes to directory
  839. structure.  For example, suppose one directory tree contains a directory
  840. named `D' with some subsidiary files, and another contains a file with
  841. the same name `D'.  `diff -r' does not output enough information for
  842. `patch' to transform the the directory subtree into the file.
  843.    There should be a way to specify that a file has been deleted without
  844. having to include its entire contents in the patch file.  There should
  845. also be a way to tell `patch' that a file was renamed, even if there is
  846. no way for `diff' to generate such information.
  847.    These problems can be fixed by extending the `diff' output format to
  848. represent changes in directory structure, and extending `patch' to
  849. understand these extensions.
  850. File: diff.info,  Node: Special Files,  Next: Unusual File Names,  Prev: Changing Structure,  Up: Shortcomings
  851. Files that are Neither Directories Nor Regular Files
  852. ----------------------------------------------------
  853.    Some files are neither directories nor regular files: they are
  854. unusual files like symbolic links, device special files, named pipes,
  855. and sockets.  Currently, `diff' treats symbolic links like regular
  856. files; it treats other special files like regular files if they are
  857. specified at the top level, but simply reports their presence when
  858. comparing directories.  This means that `patch' cannot represent changes
  859. to such files.  For example, if you change which file a symbolic link
  860. points to, `diff' outputs the difference between the two files, instead
  861. of the change to the symbolic link.
  862.    `diff' should optionally report changes to special files specially,
  863. and `patch' should be extended to understand these extensions.
  864. File: diff.info,  Node: Unusual File Names,  Next: Arbitrary Limits,  Prev: Special Files,  Up: Shortcomings
  865. File Names that Contain Unusual Characters
  866. ------------------------------------------
  867.    When a file name contains an unusual character like a newline or
  868. white space, `diff -r' generates a patch that `patch' cannot parse.
  869. The problem is with format of `diff' output, not just with `patch',
  870. because with odd enough file names one can cause `diff' to generate a
  871. patch that is syntactically correct but patches the wrong files.  The
  872. format of `diff' output should be extended to handle all possible file
  873. names.
  874. File: diff.info,  Node: Arbitrary Limits,  Next: Large Files,  Prev: Unusual File Names,  Up: Shortcomings
  875. Arbitrary Limits
  876. ----------------
  877.    GNU `diff' can analyze files with arbitrarily long lines and files
  878. that end in incomplete lines.  However, `patch' cannot patch such
  879. files.  The `patch' internal limits on line lengths should be removed,
  880. and `patch' should be extended to parse `diff' reports of incomplete
  881. lines.
  882. File: diff.info,  Node: Large Files,  Next: Ignoring Changes,  Prev: Arbitrary Limits,  Up: Shortcomings
  883. Handling Files that Do Not Fit in Memory
  884. ----------------------------------------
  885.    `diff' operates by reading both files into memory.  This method
  886. fails if the files are too large, and `diff' should have a fallback.
  887.    One way to do this is to scan the files sequentially to compute hash
  888. codes of the lines and put the lines in equivalence classes based only
  889. on hash code.  Then compare the files normally.  This does produce some
  890. false matches.
  891.    Then scan the two files sequentially again, checking each match to
  892. see whether it is real.  When a match is not real, mark both the
  893. "matching" lines as changed.  Then build an edit script as usual.
  894.    The output routines would have to be changed to scan the files
  895. sequentially looking for the text to print.
  896. File: diff.info,  Node: Ignoring Changes,  Prev: Large Files,  Up: Shortcomings
  897. Ignoring Certain Changes
  898. ------------------------
  899.    It would be nice to have a feature for specifying two strings, one in
  900. FROM-FILE and one in TO-FILE, which should be considered to match.
  901. Thus, if the two strings are `foo' and `bar', then if two lines differ
  902. only in that `foo' in file 1 corresponds to `bar' in file 2, the lines
  903. are treated as identical.
  904.    It is not clear how general this feature can or should be, or what
  905. syntax should be used for it.
  906. File: diff.info,  Node: Bugs,  Prev: Shortcomings,  Up: Projects
  907. Reporting Bugs
  908. ==============
  909.    If you think you have found a bug in GNU `cmp', `diff', `diff3',
  910. `sdiff', or `patch', please report it by electronic mail to
  911. `bug-gnu-utils@prep.ai.mit.edu'.  Send as precise a description of the
  912. problem as you can, including sample input files that produce the bug,
  913. if applicable.
  914.    Because Larry Wall has not released a new version of `patch' since
  915. mid 1988 and the GNU version of `patch' has been changed since then,
  916. please send bug reports for `patch' by electronic mail to both
  917. `bug-gnu-utils@prep.ai.mit.edu' and `lwall@netlabs.com'.
  918.